Update taffy to 0.9 and fix Grid errors #21240#21672
Update taffy to 0.9 and fix Grid errors #21240#21672alice-i-cecile merged 11 commits intobevyengine:mainfrom
Conversation
| .collect::<Vec<_>>(), | ||
| grid_row: node.grid_row.into(), | ||
| grid_column: node.grid_column.into(), | ||
| ..Default::default() |
There was a problem hiding this comment.
The fields added are dummy, item_is_replaced, grid_template_areas, grid_template_column_names, grid_template_row_names. Not sure if this should be using their default or we should add these fields and have our own default.
There was a problem hiding this comment.
dummy is just phantomdata. grid_template_areas, grid_template_column_names, and grid_template_row_names should all be left at their default values for now.
I'm confused about is_replaced. The CoreStyle trait seems to map it to is_compressible_replaced which isn't quite same thing as a replaced element, like a form field isn't compressible normally?
crates/bevy_ui/src/layout/convert.rs
Outdated
| Val::Px(val) | ||
| .into_length_percentage(context) | ||
| .into_raw() | ||
| .value(), |
There was a problem hiding this comment.
These rather verbose conversions are due to the fact that we do some math in into_length_percentage and into_length_percentage_auto, I would like to refactor the Val type story but this keeps the behavior the same
crates/bevy_ui/src/layout/convert.rs
Outdated
| ) -> taffy::style::GridTemplateComponent<S> | ||
| where | ||
| S: CheapCloneStr, | ||
| { |
There was a problem hiding this comment.
This was an add things until it compiles moment, if anyone can explain what the generics mean here I would appreciate it
There was a problem hiding this comment.
Taffy is now generic over a String-like type (which allows for named grid lines and named grid areas to be specified). Bevy should feel free to pick a concrete type such as Arc<str>, string_cache::Atom (or even String, but the idea is that such strings are cheaply cloneable).
If you're not actually using the named lines/areas feature (and thus such types will never actually be constructed) then you might consider Box<String> which would keep the size impact minimal.
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
| } | ||
| } | ||
|
|
||
| pub(crate) struct BevyTaffyTree<T>(TaffyTree<T>); |
There was a problem hiding this comment.
This is sort of a patch for an issue with Taffy:
ccbrown/iocraft#119 (comment)
Eventually it will be fixed in
DioxusLabs/taffy#823
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
I'll try and make time to take a look at this later today, chase me up about it if I haven't. |
crates/bevy_ui/src/layout/convert.rs
Outdated
| Val::VMin(val) | ||
| .into_length_percentage(context) | ||
| .into_raw() | ||
| .value(), |
There was a problem hiding this comment.
I believe Taffy has an Into implementation for this conversion
crates/bevy_ui/src/layout/convert.rs
Outdated
| MinTrackSizingFunction::Px(val) => taffy::style::MinTrackSizingFunction::length( | ||
| Val::Px(val) | ||
| .into_length_percentage(context) | ||
| .into_raw() | ||
| .value(), |
There was a problem hiding this comment.
I think just:
| MinTrackSizingFunction::Px(val) => taffy::style::MinTrackSizingFunction::length( | |
| Val::Px(val) | |
| .into_length_percentage(context) | |
| .into_raw() | |
| .value(), | |
| MinTrackSizingFunction::Px(val) => Val::Px(val).into_length_percentage(context).into(), |
should work, and so on for the rest.
There was a problem hiding this comment.
Changed this, but left the two where its actually necessary
crates/bevy_ui/src/layout/convert.rs
Outdated
| MaxTrackSizingFunction::Px(val) => taffy::style::MaxTrackSizingFunction::length( | ||
| Val::Px(val) | ||
| .into_length_percentage(context) | ||
| .into_raw() | ||
| .value(), | ||
| ), |
There was a problem hiding this comment.
Same here:
| MaxTrackSizingFunction::Px(val) => taffy::style::MaxTrackSizingFunction::length( | |
| Val::Px(val) | |
| .into_length_percentage(context) | |
| .into_raw() | |
| .value(), | |
| ), | |
| MaxTrackSizingFunction::Px(val) => Val::Px(val).into_length_percentage(context).into(), |
| } | ||
| } | ||
|
|
||
| pub(crate) struct BevyTaffyTree<T>(TaffyTree<T>); |
There was a problem hiding this comment.
The name's a bit too long and ugly, maybe just:
| pub(crate) struct BevyTaffyTree<T>(TaffyTree<T>); | |
| pub(crate) struct UiTree<T>(TaffyTree<T>); |
would be better, or something like that.
| #[expect(unsafe_code, reason = "TaffyTree is safe as long as calc is not used")] | ||
| /// SAFETY: Taffy Tree becomes thread unsafe when you use the calc feature, which we do not implement | ||
| unsafe impl Send for BevyTaffyTree<NodeMeasure> {} | ||
|
|
||
| #[expect(unsafe_code, reason = "TaffyTree is safe as long as calc is not used")] | ||
| /// SAFETY: Taffy Tree becomes thread unsafe when you use the calc feature, which we do not implement | ||
| unsafe impl Sync for BevyTaffyTree<NodeMeasure> {} |
There was a problem hiding this comment.
Couldn't we just implement the traits for UiSurface itself?
There was a problem hiding this comment.
Probably better to do it like it's already being done here I think. Lest we accidently add some non-Send field to another part of UiSurface. Implementing Deref and DerefMut for BevyTaffyTree would probably make this more ergonomic.
There was a problem hiding this comment.
Yeah it's not a user facing API anyway, so the extra friction doesn't really matter. We could hide it completely even, and add an accessor to UiSurface that returns a reference to the inner TaffyTree value.
There was a problem hiding this comment.
Since it will be removed after DioxusLabs/taffy#855 or similar work goes through, I think its nicer if it's a little separated like this.
There was a problem hiding this comment.
Renamed to UiTree
…21672) # Objective - bevyengine#21240 - Update taffy to 0.9.1 and grid placement with start and ends works again. ## Solution I had to make some rather un-ergonomic changes I would like advice on, so I've left comments below. ## Testing - Pending... --- ## Showcase <img width="912" height="740" alt="Screenshot 2025-10-27 at 8 18 50 PM" src="https://github.com/user-attachments/assets/50ec2de2-288f-4f8a-9e20-216bd9d1474d" /> Fixes issue with grid start and ends...
…21672) # Objective - bevyengine#21240 - Update taffy to 0.9.1 and grid placement with start and ends works again. ## Solution I had to make some rather un-ergonomic changes I would like advice on, so I've left comments below. ## Testing - Pending... --- ## Showcase <img width="912" height="740" alt="Screenshot 2025-10-27 at 8 18 50 PM" src="https://github.com/user-attachments/assets/50ec2de2-288f-4f8a-9e20-216bd9d1474d" /> Fixes issue with grid start and ends...
Objective
Solution
I had to make some rather un-ergonomic changes I would like advice on, so I've left comments below.
Testing
Showcase
Fixes issue with grid start and ends...